Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable passing vars to configure_file with flags during build [BUILD-391] #11

Closed
wants to merge 1 commit into from

Conversation

krisukox
Copy link
Contributor

@krisukox krisukox commented Oct 28, 2022

In Bazel, we can neither concatenate dict select (Bazel ticket):

vars = select({
    "//:config-1": {"var1": "ON"},
    "//conditions:default": {"var1": "OFF"},
}) + select({
    "//:config-2": {"var2": "ON"},
    "//conditions:default": {"var2": "OFF"},
}),

nor use select inside a dict:

vars = {
    "var1": select({
        "//:config-1": "ON",
        "//conditions:default", "OFF"
    }),
    "var2": select({
        "//:config-2": "ON",
        "//conditions:default", "OFF"
    }),
},

That's why to enable passing vars to configure_file, we have to use list instead of dict.
List which is passed to configure_file contains vars in the following format: <key>=<value>. Vars which don't contain equal sign are skipped.

I defined a few macros to use configure_file in a more elegant way:
var - define var
config_var - define var that relies on config_setting
config_flag - define flag along with config_setting

PR tested here:
https://github.com/swift-nav/libpal/pull/275
https://github.com/swift-nav/libswiftnav-private/pull/403
https://github.com/swift-nav/gnss-converters-bazel/pull/8

Copy link
Contributor

@jungleraptor jungleraptor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine for just us, but it's asking a lot for the end users.

I've spent quite a bit of time today seeing if there's something simpler or more intuitive.

I got close with trying to wrap configure_file in a macro, and abusing kwargs, but it wouldn't bind the select object to the string when passed to the rule: bazelbuild/bazel#3902

I'm leaning toward not changing the API, and just having a config setting for every permutation that you can select on that returns the entire dict.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants